﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Domaine.Contracts;
using Domaine.Entity;
using Infrastructure.Data.UnitOfWork;
using Inftastructure.Data.Core;
using System.Data.Entity;
namespace Infrastructure.Data. Repository
{
  public  class MemberShipRepository : Repository<Membership>, IMemberShipRepository
    {

         #region Members

        IMembershipUnitOfWork _currentUnitOfWork;

        #endregion

        #region Constructor

        /// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="unitOfWork">Associated unit of work</param>
        public MemberShipRepository(IMembershipUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
            _currentUnitOfWork = unitOfWork;
        }
       
        #endregion

        #region added methods
        public  IEnumerable<Membership> GetFilteredFullElements(System.Linq.Expressions.Expression<Func<Membership, bool>> filter)
        {
            var set=GetSet();
            return set.Include("User").Where(filter)
                           .AsEnumerable();
        }
        public  IEnumerable<Membership> GetPagedFullElements (int pageIndex, int pageCount)
        {
            var set = GetSet();

            return set.Include("User")
                          .Skip(pageCount * pageIndex)
                          .Take(pageCount)
                          .AsEnumerable();
             
        }

        public  Membership GetFullElemnt(Guid id)
        {
            var set = GetSet();
            if (id == Guid.Empty)
                 return null;
            return set.Include("User").FirstOrDefault (m=>m.UserID==id);
               
        }
        #endregion

    }
}
